﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Inicio.Entities;
using System.Data.SqlServerCe;

namespace Inicio.Core.Repositories
{
    public class ProvinceRepositorie
    {
        public List<Province> LoadProvinces(string conec, int countryId)
        {
            List<Province> provinces = new List<Province>();

            using (SqlCeConnection cn = new SqlCeConnection(conec))
            {
                cn.Open();
                using (SqlCeCommand cmd = new SqlCeCommand(
                    "select id, provinceName from Province "
                        + "where("
                            + string.Format("{0}=countryId)  ORDER BY provinceName ASC", countryId), cn))
                {
                    using (SqlCeDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            provinces.Add(new Province((int)reader["id"], reader["provinceName"].ToString()));
                        }
                    }
                }
            }
            return provinces;
        }
    }
}
